package com.supplychain.scm.core.delay.listener;

import com.supplychain.scm.core.delay.exception.MessageConversionException;
import com.supplychain.scm.core.delay.message.MessageConverter;
import com.supplychain.scm.core.delay.message.QueueMessage;
import com.supplychain.scm.core.delay.message.RedissonMessage;
import org.springframework.messaging.Message;

import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * @author liyang
 * @version 1.0.0
 * @ClassName BatchMessageConverter
 * @createTime 17:17:00 2022/10/14
 */
public interface BatchMessageConverter extends MessageConverter {

    @Override
    default QueueMessage<?> toMessage(Object payload, Map<String, Object> headers) throws MessageConversionException {
        throw new UnsupportedOperationException("please see [toListMessage] method");
    }

    @Override
    default Object fromMessage(RedissonMessage redissonMessage) throws MessageConversionException {
        return this.fromMessage(Collections.singletonList(redissonMessage));
    }

    List<QueueMessage<?>> toListMessage(Object payload, Map<String, Object> headers);

    Message<?> fromMessage(List<RedissonMessage> redissonMessages) throws MessageConversionException;

}
